package com.share.sharedevice.controller;

import com.share.common.core.domain.R;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.sharedevice.entity.Cabinet;
import com.share.sharedevice.service.ICabinetService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "充电宝柜机接口管理")
@RestController
@RequestMapping("/cabinet")
public class CabinetController extends BaseController {

    @Autowired
    private ICabinetService cabinetService;

    /**
     * 获取充电宝柜机列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Cabinet cabinet){

        startPage();
        List<Cabinet> cabinetList = cabinetService.selectCabinetList(cabinet);
        return getDataTable(cabinetList);
    }

    /**
     * 根据id获取充电宝柜机
     */
    @GetMapping("/{id}")
    public R<Cabinet> getById(@PathVariable("id") Long id){

        Cabinet cabinet = cabinetService.getCabinetById(id);
        return R.ok(cabinet);
    }

    /**
     * 删除充电宝柜机
     */
    @DeleteMapping("/{ids}")
    public R<Cabinet> delete(@PathVariable List<Long> ids){
        cabinetService.deleteByIds(ids);
        return R.ok();
    }

    /**
     * 添加充电宝柜机
     */
    @PostMapping
    public R<Cabinet> add(@RequestBody Cabinet cabinet){
        cabinetService.add(cabinet);
        return R.ok();
    }

    /**
     * 修改充电宝柜机
     */
    @PutMapping
    public R<Cabinet> updateCabinet(@RequestBody Cabinet cabinet){
        cabinetService.updateCabinet(cabinet);
        return R.ok();
    }

    /**
     * 根据编号查询未使用的充电宝柜机
     */
    @GetMapping("/searchNoUseList/{keyword}")
    public AjaxResult searchNoUseList(@PathVariable String keyword){
        List<Cabinet> cabinetList = cabinetService.searchNoUseList(keyword);
        return success(cabinetList);
    }
}
